<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.ce.util.*" %>
<%@ page import="com.ce.framework.context.*" %>
<%@ page import="com.ce.framework.util.*" %>
<%@ page import="com.ce.sys.login.model.*" %>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%
String path = FrameworkContext.getPath();
int fileSizeLimit = RegeditUtil.getRegeditIntValue(RegeditUtil.FILEUPLOAD_FILE_MAX_SIZE);
int totalUploadSize = RegeditUtil.getRegeditIntValue(RegeditUtil.FILEUPLOAD_MAX_SIZE);
String fileTypeDescription = request.getParameter("fileTypeDescription");
String fileTypes = request.getParameter("fileTypes");
if(StringUtil.isBlank(fileTypeDescription)){
	fileTypeDescription = "所有文件(*.*)";
}
if(StringUtil.isBlank(fileTypes)){
	fileTypes = "*.*";
}
%>
<html>  
<head>  
<title>  
文件上传
</title>
<!-- 单位文件大小限制：SYS_FILE_UPLOAD_FILE_MAX_SIZE，总文件大小限制：SYS_FILE_UPLOAD_MAX_SIZE -->
<%@ include file="/common/common.jsp"%>

<style type="text/css"> 
body{overflow:hidden;}
.Menubox {width:100%;height:28px;line-height:28px;margin:3px 0px;}
.Menubox table{margin:0px;padding:0px;}
.Menubox td{cursor:pointer;border-bottom:1px solid #83bbd9;width:96px;text-align:center;color:#949694;background:url(<%=path%>/images/200801081251340.gif);height:27px;line-height:27px;}
.Menubox td.hover{padding:0px;background:#fff;width:96px;border-left:1px solid #83bbd9;border-top:1px solid #83bbd9;border-right:1px solid #83bbd9;border-bottom:1px solid #fff;background:url(<%=path%>/images/200801081249070.gif);color:#046b9a;height:27px;line-height:27px;}
#content div{width:100%;border:0px solid red;}
.btn-span{width:100%;display:block;border:0px solid red;text-align:right;margin:6px 160px 0px 0px;}
</style>
<script type="text/javascript" src="<%=path%>/js/swfobject.js"></script><%--
<script type="text/javascript" src="<%=path%>/js/jsdebug/logger.js"></script>
--%><script type="text/javascript">
if(!window._$)window._$=function(id){return document.getElementById(id)}
var frmUrl = {tab_div3_frm:'<%=path%>/pub/upload/PubUpload_search.action?rows=10&type=0',
				tab_div4_frm:'<%=path%>/pub/upload/PubUpload_search.action?rows=10&type=1'}
function setTab(name,cursel){
	for(i=1;i<=100;i++){
		var menu=document.getElementById(name+i);
		var div = _$(name+'_div'+i);
		if(!menu)break;
		menu.className = i==cursel?"hover":"";
		div.style.display=i==cursel?"":"none";
		if(i==cursel&&_$(name+'_div'+i+'_frm')){
			_$(name+'_div'+i+'_frm').src = frmUrl[name+'_div'+i+'_frm'];
		}
	}
	
}

</script>
</head> 
<body  bgcolor="#ffffff">
<div class="Menubox">
<table width=100% border="0" align="center" cellpadding="0" cellspacing="0"><tr>
<td nowrap style="width:27;cursor:default;" >&nbsp;</td>
<td nowrap id="tab1" onClick="setTab('tab',1)" <%if(!RegeditUtil.getRegeditBoolValue("DEFAULT_SHOW_COMMONUPLOAD")) out.print("class=hover"); %> >即时上传</td>
<td nowrap id="tab2" onClick="setTab('tab',2)" <%if(RegeditUtil.getRegeditBoolValue("DEFAULT_SHOW_COMMONUPLOAD")) out.print("class=hover"); %>>普通上传</td>
<td nowrap id="tab3" onClick="setTab('tab',3)" >历史上传</td>
<td nowrap id="tab4" onClick="setTab('tab',4)" >收藏夹</td>
<td id="tab100" style="width:90%;cursor:default;" >&nbsp;</td>
</tr></table>
</div>
<div id="content">
<div id="tab_div1"  <%if(RegeditUtil.getRegeditBoolValue("DEFAULT_SHOW_COMMONUPLOAD")) out.print("style='display:none;width:100%;'"); %>>
</div>
<script>
var swf = new SWFObject("<%=path %>/pub/upload/upload.swf", "uploadswf", "100%", "100%", "9", "#FFFFFF");
swf.addVariable('serverFileDesc','${oldFileDesc}');
swf.addVariable('fileSizeLimit','<%=fileSizeLimit%>');
swf.addVariable('totalUploadSize','<%=totalUploadSize%>');
swf.addVariable('fileTypeDescription','<%=fileTypeDescription%>');
swf.addVariable('fileTypes','<%=fileTypes%>');
swf.addVariable('completeFunction','uploadComplete');
swf.addVariable('uploadType','${type}');
swf.addVariable('userId','<%=User.getUserId() %>');
swf.addVariable('uploadPage','<%=path+"/pub/upload/PubUpload_flashAddFile.action"%>');
swf.addVariable('delFilePage','<%=path+"/pub/upload/PubUpload_flashDelFiles.action"%>');
swf.addVariable('SSO_ID',$.cookie('SSO_ID'));
swf.write('tab_div1');
</script>
<div id="tab_div2"  <%if(!RegeditUtil.getRegeditBoolValue("DEFAULT_SHOW_COMMONUPLOAD")) out.print("style='display:none;width:100%;'"); %>>
	<s:form action="PubUpload_uploadFiles" enctype="multipart/form-data" method="post">
		<s:textarea style="display:none" name="targetId" id="targetId" />
		<s:textarea style="display:none" name="targetName" id="targetName" />
		<s:textarea style="display:none" name="targetUrl" id="targetUrl" />
		<s:textarea style="display:none" name="fileIds" />
		<s:textarea style="display:none" name="urlSplit" id="urlSplit"/>
		<s:textarea style="display:none" name="img" id="img" />
		<s:hidden name="delIds"/>
		<s:hidden name="type"/>
		<table width="100%">
		<tr><td>
		<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
		<caption style="font-size:22;color:#0000FF">上传附件</caption>
			<tr>
				<td width="10%" align="center">
		<table id="fileTbl" style="height:" width="100%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
			<tr bgcolor="#CCCCCC">
				<td height="20" width="10%" align="center" bgcolor="#D9E9FF">
					序号
				</td>
				<td width="70%" align="center" bgcolor="#D9E9FF">
					文件名称
				</td>
				<td width="10%" align="center" bgcolor="#D9E9FF">
					文件大小
				</td>
				<td width="10%" align="center" bgcolor="#D9E9FF">
					删除
				</td>
			</tr>
			<% int i=1;%>
			<s:iterator value="oldFile" id="list">
			<tr >
				<td width="10%" align="center" bgcolor="#FFFFFF"><%=i++%></td>
				<td width="70%" align="center" bgcolor="#FFFFFF"><s:property value="#list.vcFilename"/></td>
				<td width="10%" align="center" bgcolor="#FFFFFF"><s:property value="#list.VcFilesize" /></td>
				<td width="10%" align="center" bgcolor="#FFFFFF" >
				<a href="javascript:void(0);" onClick="delRow(this,'<s:property value="#list.vcId"/>');">删除</a>
				</td>
			</tr>
			</s:iterator>
			</table>
			</td>
			</tr>
		</table>
		</td></tr>
		<tr><td ><table width="100%">
			<tr bgcolor="#CCCCCC">
				<td colspan="4" bgcolor="#FFFFFF" style="color:red" align="right">
					注意：单个文件请不要超过10M，总文件大小请不要超过50M,否则会导致上传失败！
				</td>
			</tr>
			<tr bgcolor="#CCCCCC">
				<td colspan="4" bgcolor="#FFFFFF" align="center">
				<logic:notPresent name="files">
					<a class="easyui-linkbutton" href="javascript:void(0);" onClick="addRow();">添加一行</a>
				</logic:notPresent>
					<a class="easyui-linkbutton" href="javascript:void(0);" onClick="submitFile();this.disabled=true;">上传附件</a>
					
				</td>
			</tr>
		</table></td></tr>
		</table>
</s:form>
</div>
<div id="tab_div3" style="display:none;width:100%;">
<iframe id="tab_div3_frm" src="" style="width:100%;" frameborder="0"></iframe>
<br>
<span class="btn-span"><a href="javascript:void(0);" class="easyui-linkbutton" onClick="saveFiles('tab_div3_frm')">确  定</a></span>
</div>
<div id="tab_div4" style="display:none;width:100%;">
<iframe id="tab_div4_frm" src="" style="width:100%;" frameborder="0"></iframe>
<br>
<span class="btn-span"><a href="javascript:void(0);" class="easyui-linkbutton" onClick="saveFiles('tab_div4_frm')">确  定</a></span>
</div>
</div>
</body>  

</html>  

<script language="javascript">
function resize(){
	var dom = document.body||document.documentElement;
	_$('tab_div1').style.height = _$('tab_div3').style.height = _$('tab_div4').style.height = dom.clientHeight - 50;
	_$('tab_div3_frm').style.height = _$('tab_div4_frm').style.height = dom.clientHeight-80;
}
window.onresize = resize;
resize();

var opennew = window==top;
var  fileNum = 0;
function addRow(fileName,fileId){
	var fileTbl = $('#fileTbl')[0];
	var row = fileTbl.insertRow(-1);
	var num = fileTbl.rows.length;
	var cell = row.insertCell(-1);
	cell.setAttribute("align","center");
	cell.setAttribute("bgColor","#FFFFFF");
	cell.innerHTML = num-1;
	cell = row.insertCell(-1);
	cell.setAttribute("align","center");
	cell.setAttribute("bgColor","#FFFFFF");
	cell.innerHTML = '<input style="width:90%" type=file  name="files"  value="">';
	cell = row.insertCell(-1);
	cell.setAttribute("align","center");
	cell.setAttribute("bgColor","#FFFFFF");
	cell.innerHTML = "未知";
	cell = row.insertCell(-1);
	cell.setAttribute("align","center");
	cell.setAttribute("bgColor","#FFFFFF");
	cell.setAttribute("value",fileId!=null?fileId:"");
	cell.innerHTML = '<a href="javascript:void(0);" onclick="delRow(this);">删除</a>';
}
addRow();

function delRow(td,fileId){
	var fileTbl = $('#fileTbl')[0];
	var f = document.forms[0];
	if(fileId!=null && fileId!=""){
		f.delIds.value += fileId+",";
	    f.fileIds.value = document.forms[0].fileIds.value.replace(fileId,"");
	}
	fileTbl.deleteRow(td.parentNode.parentNode.rowIndex);
	for(i=1;i<fileTbl.rows.length;i++){
		if(fileTbl.rows[i].cells[0].innerHTML!=i)
			fileTbl.rows[i].cells[0].innerHTML = i;
	}
}

function submitFile(){
	var fileTbl = $('#fileTbl')[0];
	var form = document.forms[0];
	for(i=fileTbl.rows.length-1;i>0;i--){
		if(fileTbl.rows[i].cells[1].firstChild.value=="")
			fileTbl.deleteRow(i);
	}
	if(form.delIds.value=="" && fileTbl.rows.length==1)window.close();
	document.forms[0].submit();
}
var targetId = $('#targetId').val();
var targetName = $('#targetName').val();
var targetUrl = $('#targetUrl').val();
function uploadComplete(ids,names){
	var urls = '';
	var urlSplit = $('#urlSplit').val();
	if(urlSplit=='')
		urlSplit = ',';
	for(var i=0;i<ids.length;i++){
		urls += urlSplit+($('#img').val()=='true'?'<img src':'<a href')+'="<%=path%>/pub/upload/PubUpload_loadFile.action?vcId='+ids[i]+'">'+($('#img').val()=='true'?'':names[i]+'</a>');
	}
	if(urls.length>0)urls = urls.substr(urlSplit.length);
	var doc = opennew?window.opener.document:parent.document;
	try{
		tid=doc.getElementById(targetId);
		tid.value = ids.join(','); tid.innerText = tid.value;
	}catch(e){;}
	try{
		tname=doc.getElementById(targetName);
		tname.value = names.join(','); tname.innerText = tname.value;
	}catch(e){;}
	try{
		turl=doc.getElementById(targetUrl);
		turl.value = urls; turl.innerHTML = turl.value;
	}catch(e){;}
	if(opennew)window.close();
	else parent.hideUploadWindow();
}
function saveFiles(id){
	var rows = _$(id).contentWindow.$('#searchTable').datagrid('getSelections');
	if(rows.length==0){
		alert('请选择文件!');
		return;
	}
	var ids = [];names=[];
	for(var i=0;i<rows.length;i++){
		ids.push(rows[i].vcId);
		names.push(rows[i].vcFilename);
	}
	uploadComplete(ids,names);
}

</script>
